#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#define INF 1000000000
#define MAXN 100000
#define MAXM 100005
#define s(T) scanf("%d", &T)
using namespace std;

int N, Q;
int L[MAXN], R[MAXN];
int b[MAXN];

struct segT{
    int beg[4*MAXN];
    int end[4*MAXN];
    int val[4*MAXN];

    void init(int pos, int start, int finish){
        beg[pos] = start;
        end[pos] = finish;
        val[pos] = INF;

        if (start < finish){
            int mid = (start+finish) >> 1;
            int left = pos << 1;
            int right = left + 1;

            init(left, start, mid);
            init(right, mid+1, finish);
        }
    }

    void update(int idx, int x, int pos){
        if (beg[pos] == idx && end[pos] == idx){
            val[pos] = x;
            return;
        }
        if (beg[pos] > idx || idx > end[pos]) return;

        int left = pos << 1;
        int right = left + 1;

        update(idx, x, left);
        update(idx, x, right);
        val[pos] = min(val[left], val[right]);
    }

    int query(int pos, int start, int finish){
        if (beg[pos] >= start && end[pos] <= finish)
            return val[pos];
        if (beg[pos] > finish || end[pos] < start)
            return INF;
        int left = pos << 1;
        int right = left + 1;
        return min(query(left, start, finish), query(right, start, finish));
    }
};

segT pos, neg;

void input(){
    s(N);
    for (int i=0;i<N;i++){
        s(b[i]);
    }
    s(Q);
    for (int i=0;i<Q;i++){
        s(L[i]);
        s(R[i]);
    }
}

void solve(){
    pos.init(1, 0, N-1);
    neg.init(1, 0, N-1);
    for (int i=0;i<N;i++){
        pos.update(i, b[i], 1);
        neg.update(i,-b[i], 1);
    }
    for (int i=0;i<Q;i++){
        int back = pos.query(1, L[i], R[i]);
        int f1 = -neg.query(1, 0, L[i]-1);
        int f2 = -neg.query(1, L[i], R[i]);
        int f3 = -neg.query(1, R[i]+1, N-1);
        double front = max(f1/1.0, max((f2-back)/2.0, f3/1.0));
        printf("%.1lf\n", back + front + 0.01);
    }
}

int main()
{
    freopen("MSTICK.txt","r", stdin);
    input();
    solve();
    return 0;
}
